package com.runner.track.design;

import java.util.ArrayList;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.runner.track.Coin;
import com.runner.utility.Constants;
import com.runner.utility.Locator;

public abstract class TrackDesign implements Constants {

	public static int SEMI_CIRCLE_COUNT = 9;

	public static ArrayList<Coin> addInverseArc(float x, float y, int count) {
		ArrayList<Coin> coins = new ArrayList<Coin>();
		float lengthX = COIN_WIDTH * 0.8f * SEMI_CIRCLE_COUNT * Locator.getxSpriteScale();
		float lengthY = -COIN_HEIGHT * 0.8f * SEMI_CIRCLE_COUNT * Locator.getySpriteScale();
		float degreesPerCoin = 180 / (SEMI_CIRCLE_COUNT - 1);
		int mid = count / 2;

		int start = SEMI_CIRCLE_COUNT / 2 - mid;
		int end = SEMI_CIRCLE_COUNT / 2 + mid;
		for (int i = start; i < end + 1; i++) {
			Coin c = new Coin(new Vector2(x + MathUtils.cos((i) * degreesPerCoin * MathUtils.degreesToRadians) * lengthX, y
					+ MathUtils.sin((i) * degreesPerCoin * MathUtils.degreesToRadians) * lengthY));
			coins.add(c);
		}

		return coins;
	}
	
	public static ArrayList<Coin> addArc(float x, float y, int count) {
		ArrayList<Coin> coins = new ArrayList<Coin>();
		float lengthX = COIN_WIDTH * 0.8f * SEMI_CIRCLE_COUNT * Locator.getxSpriteScale();
		float lengthY = COIN_HEIGHT * 0.8f * SEMI_CIRCLE_COUNT * Locator.getySpriteScale();
		float degreesPerCoin = 180 / (SEMI_CIRCLE_COUNT - 1);
		int mid = count / 2;

		int start = SEMI_CIRCLE_COUNT / 2 - mid;
		int end = SEMI_CIRCLE_COUNT / 2 + mid;
		for (int i = start; i < end + 1; i++) {
			Coin c = new Coin(new Vector2(x + MathUtils.cos((i) * degreesPerCoin * MathUtils.degreesToRadians) * lengthX, y
					+ MathUtils.sin((i) * degreesPerCoin * MathUtils.degreesToRadians) * lengthY));
			coins.add(c);
		}

		return coins;
	}

	public static ArrayList<Coin> addHalfArc(float x, float y, int count) {
		ArrayList<Coin> coins = new ArrayList<Coin>();

		float lengthX = COIN_WIDTH * 0.8f * SEMI_CIRCLE_COUNT * Locator.getxSpriteScale();
		float lengthY = COIN_HEIGHT * 0.8f * SEMI_CIRCLE_COUNT * Locator.getySpriteScale();
		float degreesPerCoin = 180 / (SEMI_CIRCLE_COUNT - 1);

		int start = SEMI_CIRCLE_COUNT / 2;
		int end = SEMI_CIRCLE_COUNT / 2 + count - 1;
		for (int i = start; i < end + 1; i++) {
			Coin c = new Coin(new Vector2(x + MathUtils.cos((i) * degreesPerCoin * MathUtils.degreesToRadians) * lengthX, y
					+ MathUtils.sin((i) * degreesPerCoin * MathUtils.degreesToRadians) * lengthY));
			coins.add(c);
		}

		return coins;
	}

	public static ArrayList<Coin> addRightHalfArc(float x, float y, int count) {
		ArrayList<Coin> coins = new ArrayList<Coin>();

		float lengthX = COIN_WIDTH * 0.8f * SEMI_CIRCLE_COUNT * Locator.getxSpriteScale();
		float lengthY = COIN_HEIGHT * 0.8f * SEMI_CIRCLE_COUNT * Locator.getySpriteScale();
		float degreesPerCoin = 180 / (SEMI_CIRCLE_COUNT - 1);

		int start = SEMI_CIRCLE_COUNT / 2;
		int end = SEMI_CIRCLE_COUNT / 2 - count;
		for (int i = start; i > end; i--) {
			Coin c = new Coin(new Vector2(x + MathUtils.cos((i) * degreesPerCoin * MathUtils.degreesToRadians) * lengthX, y
					+ MathUtils.sin((i) * degreesPerCoin * MathUtils.degreesToRadians) * lengthY));
			coins.add(c);
		}

		return coins;
	}

	public static ArrayList<Coin> addCoinRectangle(float x, float y, int width, int height) {
		ArrayList<Coin> coins = new ArrayList<Coin>();
		float xSpacing = COIN_WIDTH * 2.5f * Locator.getxSpriteScale();
		float ySpacing = COIN_HEIGHT * 2.5f * Locator.getySpriteScale();
		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				Coin c = new Coin(new Vector2(x + i * xSpacing, y + j * ySpacing));
				coins.add(c);
			}
		}
		return coins;
	}

	public static ArrayList<Coin> addCoinLine(float x, float y, int count) {
		ArrayList<Coin> coins = new ArrayList<Coin>();
		float xSpacing = COIN_WIDTH * 2.5f * Locator.getxSpriteScale();
		for (int i = 0; i < count; i++) {
			Coin c = new Coin(new Vector2(x + i * xSpacing, y));
			coins.add(c);
		}
		return coins;
	}

	public static ArrayList<Coin> addVerticalCoinLine(float x, float y, int count) {
		ArrayList<Coin> coins = new ArrayList<Coin>();
		float ySpacing = COIN_HEIGHT * 2.5f * Locator.getySpriteScale();
		for (int i = 0; i < count; i++) {
			Coin c = new Coin(new Vector2(x, y + i * ySpacing));
			coins.add(c);
		}
		return coins;
	}
}
